package com.huluobo.a2308douyindemo.shop

import com.huluobo.a2308douyindemo.bean.CartBean
import com.huluobo.a2308douyindemo.bean.GoodsBean
import com.huluobo.a2308douyindemo.bean.GoodsCommentBean
import com.huluobo.a2308douyindemo.mvvm.BaseViewModel
import com.huluobo.a2308douyindemo.net.ApiServiceGift
import com.huluobo.a2308douyindemo.net.Res
import com.huluobo.a2308douyindemo.utils.UnPeekLiveData
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

/**
 *  Created by LC on 2025/11/4.
 */
@HiltViewModel
class ShopViewModel @Inject constructor(private val apiServiceGift: ApiServiceGift) : BaseViewModel() {

    val getGoodsDetailSuccess by lazy { UnPeekLiveData<Res<GoodsBean>>() }
    fun getGoodsDetail(goodsId: Int) {
        executeNetwork(
            { apiServiceGift.getGoodsDetail(goodsId) },
            getGoodsDetailSuccess::setContentValue
        )
    }

    val getGoodsCommentSuccess by lazy { UnPeekLiveData<Res<List<GoodsCommentBean>>>() }
    fun getGoodsComment() {
        executeNetwork(
            { apiServiceGift.getGoodsComment() },
            getGoodsCommentSuccess::setContentValue
        )
    }

    val addToCartSuccess by lazy { UnPeekLiveData<Res<Any>>() }
    fun addToCart(map: Map<String, Any>) {
        executeNetwork(
            { apiServiceGift.addToCart(mapToJson(map)) },
            addToCartSuccess::postValue
        )
    }

    val getCartSuccess by lazy { UnPeekLiveData<Res<List<CartBean>>>() }
    fun getCart() {
        executeNetwork(
            { apiServiceGift.getCart() },
            getCartSuccess::setContentValue
        )
    }

    val deleteCartSuccess by lazy { UnPeekLiveData<Res<String>>() }
    fun deleteCart(map: Map<String, Any>) {
        executeNetwork(
            { apiServiceGift.deleteCart(mapToJson(map)) },
            deleteCartSuccess::setContentValue
        )
    }
}